package com.smmisia.article.utils;

import java.security.SecureRandom;

/**
 * 邀请码生成
 */
public class InviteCodeGenerator {
    // 定义字符池
    private static final String CHAR_POOL = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    private static final SecureRandom random = new SecureRandom();

    // 生成邀请码方法
    public static String generateInviteCode(int length) {
        StringBuilder inviteCode = new StringBuilder(length);
        for (int i = 0; i < length; i++) {
            int index = random.nextInt(CHAR_POOL.length());
            inviteCode.append(CHAR_POOL.charAt(index));
        }
        return inviteCode.toString();
    }
}
